package com.patterns.singleton.SomSingleton;

import java.util.Random;
import java.util.Vector;

/**
 * Created by Xiao Yiyun on 2017/4/12.
 */
public class Emperor {

    private static int max = 2;
    private static Vector<String> names = new Vector<String>();
    private static Vector<Emperor> emperors = new Vector<Emperor>();
    private static int count = 0;

    static {
        for (int i=0; i<max; i++) {
            emperors.add(new Emperor("皇帝" + i));
        }
    }

    private Emperor(String name) {
        names.add(name);
    }

    public static Emperor getInstance() {
        Random random = new Random();
        count = random.nextInt(max);
        return emperors.get(count);
    }

    public void say() {
        System.out.println(names.get(count));
    }
}
